﻿using CslgInfo.Utils.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CslgInfo.WeChatMini
{
    public partial class ApiHelper
    {
        #region Private fields
        private static volatile ApiHelper _instance = null;
        private static readonly object lockObject = new object();
        /// <summary>
        /// 基础URL
        /// </summary>
        const string baseUrl = "https://api.weixin.qq.com/";
        #endregion

        #region Instance
        /// <summary>
        /// 获取单例对象
        /// </summary>
        /// <returns></returns>
        public static ApiHelper Instance()
        {
            if (_instance == null)
            {
                lock (lockObject)
                {
                    if (_instance == null)
                    {
                        _instance = new ApiHelper();
                    }
                }
            }
            return _instance;
        }
        private ApiHelper() { }
        #endregion
        #region 基础接口
        /// <summary>
        /// 
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="appSecret"></param>
        /// <returns></returns>
        public GetAccessTokenResult GetAccessToken(string appId, string appSecret)
        {
            string url = string.Format("{0}cgi-bin/token?grant_type=client_credential&appid={1}&secret={2}", baseUrl, appId, appSecret);
            return HttpHelper.HttpGet.GetJsonResult<GetAccessTokenResult>(url);
        }
        #endregion
    }
}
